﻿using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.抖音出入库.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.抖音出入库.抖音订单
{
    public partial class Form抖音客户订单信息 : DevExpress.XtraEditors.XtraForm
    {
        public Form抖音客户订单信息()
        {
            InitializeComponent();
            this.textBox电话查询.Focus();
        }

        private void textBox电话查询_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (!String.IsNullOrWhiteSpace(this.textBox电话查询.Text))
                {
                    //  查询
                    DouyinCustomerOrderInfoDTO douyinCustomerOrderInfoDTO;
                    try
                    {
                        douyinCustomerOrderInfoDTO = 抖音Service.getOrderInfoByMobile(this.textBox电话查询.Text.Trim());
                    }
                    catch 
                    {
                        douyinCustomerOrderInfoDTO = new DouyinCustomerOrderInfoDTO();
                    }
                    //  显示客户地址信息
                    this.showAddress(douyinCustomerOrderInfoDTO.douyinAddressQueryDTO);
                    //  显示客户订单信息
                    this.showOrder(douyinCustomerOrderInfoDTO.douyinCustomerOrderRelateInfoDTOList);
                    this.textBox电话查询.Clear();
                }
            }
        }

        private void showAddress(DouyinAddressQueryDTO douyinAddressQueryDTO)
        {
            this.textBox客户名.Text = douyinAddressQueryDTO.customerName;
            this.textBox电话.Text = douyinAddressQueryDTO.mobile;
            this.textBox地址.Text = douyinAddressQueryDTO.addressProvince 
                                    + douyinAddressQueryDTO.addressCity 
                                    + douyinAddressQueryDTO.addressDistrict 
                                    + douyinAddressQueryDTO.addressStreet 
                                    + douyinAddressQueryDTO.addressDetail;
        }

        private void showOrder(List<DouyinCustomerOrderRelateInfoDTO> douyinCustomerOrderRelateInfoDTOList)
        {
            this.gridControl客户订单信息.DataSource = douyinCustomerOrderRelateInfoDTOList;
            this.bandedGridView客户订单信息.RefreshData();
        }
    }
}